package com.hhh.demo.sx.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.hhh.demo.sx.bean.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;



public class SessionUtil {

	// 获取当前的Request
	public static HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
	}

	// 获取当前的Session
	public static HttpSession getSession() {
		return getRequest().getSession();
	}

	//获取当前登录账号
	public static User getCurrentUser() {
		Object obj = getSession().getAttribute("user");
		if (obj != null && obj instanceof User) {
			return (User) obj;
		}
		return null;
	}
	//注销
	public static void removeCurrentUser() {
		getSession().removeAttribute("user");

	}
}
